Platform Explorer / Nuxeo Platform 2021.64

Component org.nuxeo.salesforce.automation.contrib

Resolution Order

849
The resolution order represents the order in which this component has been resolved by the Nuxeo Runtime framework.
You can influence this order by adding "require" tags in your component declaration, to make sure it is resolved after another component.

Contributions

XML Source

<?xml version="1.0"?>
<component name="org.nuxeo.salesforce.automation.contrib">
  <extension
          target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent"
          point="operation">
    <scriptedOperation id="Salesforce.TouchSFLibrary">
      <inputType>document</inputType>
      <outputType>document</outputType>
      <category>javascript</category>
      <param name="update" type="Boolean"/>
      <param name="record" type="Object"/>
      <script>
        <![CDATA[function run(input, params) {
            var sfobject = JSON.parse(params.record);
            var update = params.update;
            var properties = {
                 "dc:title" : sfobject.Name,
                 "sf:objectId" : sfobject.Id,
                 "sf:objectType" : sfobject.sobjectType,
                 "dc:description" : sfobject.Description || '',
            };
            if ('Amount' in sfobject) {
                properties["sf:objectAmount"] = sfobject.Amount ? sfobject.Amount.toString() : null;
            }
            if (update) {
                return Document.Update(input, { 'properties': properties });
            } else {
                var docs = Repository.Query(null, {
                    'query': "SELECT * FROM Document WHERE ecm:isTrashed = 0 AND sf:objectId = '" + sfobject.Id + "' AND ecm:isVersion = 0 AND ecm:mixinType != 'HiddenInNavigation'",
                });
                if (docs.length > 0) {
                    return Repository.GetDocument(null, { 'value': docs[0].id });
                } else {
                    return Document.Create(input, {
                        "type" : "Workspace",
                        "name" : sfobject.Name.replace(/[^A-Za-z0-9_.-]+/g, '-'),
                        "properties" : properties
                    });
                }
            }
        }]]>
      </script>
    </scriptedOperation>

    <scriptedOperation id="Salesforce.LinkAsSource">
      <inputType>document</inputType>
      <outputType>document</outputType>
      <category>Salesforce</category>
      <param name="unlink" type="Boolean"/>
      <param name="record" type="Object"/>
      <script>
        <![CDATA[function run(input, params) {
            var sfobject = JSON.parse(params.record);
            Auth.LoginAs(null, {
            	'name': null
            }); // login as sys admin
            var doc = Salesforce.LinkDocument(input, {
            	'unlink': params.unlink,
            	'objectId': sfobject.Id 
            });
            Audit.LogEvent(input, {
            	'event': params.unlink ? 'DocumentUnlinkedFromSalesforceObject' : 'DocumentLinkedToSalesforceObject',
            	'category': 'Salesforce',
            	'comment': sfobject.Name + ' - ' +sfobject.Id 
            })
            return doc;
        }]]>
      </script>
    </scriptedOperation>
    
  </extension>
    
</component>